package com.yqyd.web.controller.hy.app;

import com.yqyd.common.annotation.Anonymous;
import com.yqyd.common.core.domain.R;
import com.yqyd.hy.domain.HyCategory;
import com.yqyd.hy.domain.HyGoods;
import com.yqyd.hy.domain.HyGoodsPriceRecord;
import com.yqyd.hy.dto.CategorySearchDto;
import com.yqyd.hy.dto.GoodsSearchDto;
import com.yqyd.hy.service.IHyCategoryService;
import com.yqyd.hy.service.IHyGoodsPriceRecordService;
import com.yqyd.hy.service.IHyGoodsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分类
 */
@RestController
@RequestMapping("/api/app/goods")
@CrossOrigin
public class ApiGoodsController {

    @Resource
    private IHyGoodsService goodsService;

    @Resource
    private IHyCategoryService categoryService;
    @Resource
    private IHyGoodsPriceRecordService priceRecordService;

    private static final Integer STATUS = 1 ;

    @GetMapping("/List")
    @Anonymous
    public R<List<HyGoods>> List(GoodsSearchDto dto) {
        return R.ok(goodsService.selectHyGoodsList(new HyGoods()
                .setCategoryId(dto.getCategoryId())
                .setName(dto.getKeyword())
                .setStatus(STATUS)
        ));
    }

    /**
     * 分类列表
     * @return
     */
    @GetMapping("/Category")
    @Anonymous
    public R<List<HyCategory>> Category(CategorySearchDto dto) {
        return R.ok(categoryService.selectHyCategoryListApp(new HyCategory().setName(dto.getKeyword())));
    }

    /**
     * 最新更新时间
     * @return
     */
    @GetMapping("/UpdateTime")
    @Anonymous
    public R<String> UpdateTime() {
        return R.ok(goodsService.UpdateTime());
    }

    /**
     * 价格记录
     */
    @GetMapping("/PriceRecord/{id}")
    @Anonymous
    public R<List<HyGoodsPriceRecord>> PriceRecord(@PathVariable("id") Long id) {
        // 6 条数据
        return R.ok(priceRecordService.selectHyGoodsPriceRecordList(new HyGoodsPriceRecord().setGoodsId(id)));
    }

}
